package com.frank.oss.config;

import com.frank.oss.adapter.AliCloudStorageAdapter;
import com.frank.oss.adapter.MinioStorageAdapter;
import com.frank.oss.adapter.StorageAdapter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Frank Zou
 * @version v0.0.1
 * @date 2024/2/2 15:06
 * @description
 */
@Configuration
@RefreshScope
public class StorageConfig {

    @Value("${spring.storage.type}")
    private String storageType;

    @Bean
    @RefreshScope
    public StorageAdapter storageService() {
        if ("minio".equals(storageType)) {
            return new MinioStorageAdapter();
        } else if ("aliCloud".equalsIgnoreCase(storageType)) {
            return new AliCloudStorageAdapter();
        } else {
            throw new IllegalArgumentException("暂不支持该存储类型");
        }
    }

}
